import { request } from '@umijs/max';

/** 登录 POST /system/auth/login */
export async function login(username: string, password: string) {
  return request<API.Resp<API.Token>>('/system/auth/login', {
    method: 'POST',
    data: {
      username,
      password,
    },
    skipErrorHandler: true,
  });
}

/** 更新Token POST /system/auth/refreshToken */
export async function refreshToken(refreshToken: string) {
  return request<API.Resp<API.Token>>('/system/auth/refreshToken', {
    method: 'POST',
    params: {
      refreshToken,
    },
    skipErrorHandler: true,
  });
}

/** 退出登录 POST /system/auth/logout */
export async function logout() {
  return request<API.Resp>('/system/auth/logout', {
    method: 'POST',
    skipErrorHandler: true,
  });
}

/** 查询用户信息 GET /system/auth/getPermissionInfo */
export async function getPermissionInfo() {
  return request<API.Resp<API.CurrentUser>>('/system/auth/getPermissionInfo', {
    method: 'GET',
    skipErrorHandler: true,
  });
}

/** 更新Token GET /system/auth/menu/tree/list */
export async function getMenu() {
  return request<API.Resp<API.MenuTreeNode[]>>('/system/auth/menu/tree/list', {
    method: 'GET',
    skipErrorHandler: true,
  });
}
